<template>
  <RouterView />
</template>

<script setup lang="ts">
import { RouterView, useRoute } from 'vue-router'
import { ref, onMounted } from "vue"
import { useConfig } from './stores/config'
import createAxios from './utils/axios'
import { useUserInfo } from './stores/userInfo'

onMounted(() => {
  window.onload = function () {

    //const usernfo = useUserInfo()
    //console.log('初始化的token',usernfo.getToken())  // 刷新的时候为空
    //console.log('初始化的token',usernfo.getUser())  // 刷新的时候为空
    //console.log(' 当前路由 初始化的时候获取不成功',useRoute())
    //console.log('当前路径', this.$route.path)


    // 可以用 getConfig() 替换这里的代码
    // 初始化
    const config = useConfig()
    const usernfo = useUserInfo()
    createAxios({
        url: '/frontend/home/init',
        method: 'post',
      })
        .then((res) => {
          //const config = useConfig()
          config.setPropose(res.data.propose)
          config.setTree(res.data.tree)
          config.setSite(res.data.config)
          config.setSite(res.data.user)

          usernfo.dataFill(res.data.user)
          console.log('初始化请求结果', res)
        })
        .catch((err) => {
          console.log('初始化请求失败', err)
        })



    }


    // touchstart
    document.addEventListener("touchstart", function (event) {
      if (event.touches.length > 1) {
        event.preventDefault();
      }
    });
    //  gesturestart
    document.addEventListener("gesturestart", function (event) {
      event.preventDefault();
    });
  });

  /*function dd (){
    async() =>{
      await createAxios({
          url: '/frontend/home/init',
          method: 'post',
        })
          .then((res) => {
            //const config = useConfig()
            config.setPropose(res.data.propose)
            config.setTree(res.data.tree)
            config.setSite(res.data.config)
            console.log('初始化请求结果', res)
          })
          .catch(() => {

          })
      }
    }
  }*/
</script>
